package org.itboys.ace.web.lasted;

import org.itboys.admin.service.lasted.SystemUserRoleService;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *作者：江雄
 * 描述：系统_用户角色_关联_controlloer
 * 时间：2017年2月24日.重新构建
 */
@RestController
@RequestMapping("/ace/system/user/role")
public class AceSystemUserRoleController extends BaseController{
    @Autowired
    private SystemUserRoleService userRoleService;





    /**
     * 保存
     * @param request
     * @param response
     */
    @RequestMapping(value="/saveUserRoles", method=RequestMethod.POST)
    public void saveUserRoles(@RequestParam(value="userId",required =true)Long userId,
                     @RequestParam(value="roleIds",required =true)List<Long> roleIds,
                     HttpServletRequest request, HttpServletResponse response) {
        try{

            userRoleService.saveUserRoles(userId,roleIds);
            AjaxUtils.renderText(response, CommonConstants.SUCCESS);
        }catch(Exception e){
            logger.error("SystemUser save error", e);
            e.printStackTrace();
            AjaxUtils.renderText(response, CommonConstants.FAIL);
        }
    }
    /**
     * 保存
     * @param request
     * @param response
     */
    @RequestMapping(value="/allotUserRole", method=RequestMethod.POST)
    public void allotUserRole(@RequestParam(value="userId",required =true)Long userId, HttpServletRequest request, HttpServletResponse response) {
        try{
               // userRoleService.allotUserRole(userId);
            AjaxUtils.renderJson(response,userRoleService.allotUserRole(userId));
        }catch(Exception e){
            logger.error("SystemUser save error", e);
            e.printStackTrace();
            AjaxUtils.renderText(response, CommonConstants.FAIL);
        }
    }

}
